package cn.edu.xaut.mybatisers.mall.ServiceImp;

import cn.edu.xaut.mybatisers.mall.Dao.ConsumerCommodityDao;
import cn.edu.xaut.mybatisers.mall.Entity.Commodity;
import cn.edu.xaut.mybatisers.mall.Entity.OrderOneByOne;
import cn.edu.xaut.mybatisers.mall.Service.ConsumerCommodityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.ArrayList;


@Service
@SuppressWarnings("all")
public class ConsumerCommodityServiceImp implements ConsumerCommodityService {
    
    @Autowired
    ConsumerCommodityDao consumerCommodityDao;
    
    @Override
    public PageInfo<Commodity> findCommodity(Commodity commodity, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        ArrayList<Commodity> commodities = consumerCommodityDao.findCommodity(commodity);
        return new PageInfo<>(commodities);
    }

    @Override
    public PageInfo<OrderOneByOne> getCommodityComment(Commodity commodity, int pageNum, int pageSize) throws SQLException {
        ArrayList<OrderOneByOne> commodityComment = consumerCommodityDao.getCommodityComment(commodity);
        for (OrderOneByOne o : commodityComment)
            o.setIsComment(o.getEvaluate() != null ? true : false);
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(commodityComment);
    }
}
